<template>
	<projectList :queryInterface="queryInterface" :setTableCloumns="setCloumn" projectValueAttr="projectCode">
		<template #operation>
			<el-table-column label="操作" width="120" align="center">
				<template #default="{ row }">
					<!-- v-btnPermi="{ permis: [infoPermis] }" -->
					<el-button class="zs-link" link size="small" @click="toPage(row, 'info')">查看</el-button>
					<el-divider v-if="!notShowDivider" direction="vertical" />
					<el-button v-if="!notShowEdit" class="zs-link" link size="small" @click="toPage(row, 'edit')">编辑</el-button>
				</template>
			</el-table-column>
		</template>
	</projectList>
</template>

<script setup>
	import projectList from '@/components/projectList.vue';
	import { projectListApi } from '@/api/common.js';
	import { equipmentProjectListApi, planProjectListApi } from '@/api/equipment.js';
	import { facilityProjectListApi, planFacilityProjectListApi } from '@/api/facility.js';
	import { inspectProjectListApi, InspectPlanProjectListApi } from '@/api/inspect.js';
	import { licenseProjectListApi } from '@/api/license.js';
	import { insuranceProjectListApi } from '@/api/insurance.js';
	import { suppliesProjectListApi } from '@/api/supplies.js';
	import { waterProjectListApi, waterCopyProjectListApi, electricityProjectListApi, electricityCopyProjectListApi, energyProjectListApi, publicAreaProjectListApi } from '@/api/energy.js';
	import { residenceProjectListApi, residenceDataSyncProjectListApi } from '@/api/residence.js';
	import { reactive } from 'vue';
	import { useRouter, useRoute } from 'vue-router';
	const route = useRoute();
	const router = useRouter();
	const routeName = route.name;
	// 公用的项目列表配置 key：route的name
	const configData = reactive({
		EquipmentProjectList: {
			apiName: equipmentProjectListApi,
			editPermis: 'p_btn_property_device_project_list_edit',
			infoPermis: 'p_btn_property_device_project_list_view',
			rid: 'page_property_project_device_list',
			rTitle: '设备库-设备列表',
			cloumns: [
				{ prop: 'rentalAreaSum', label: '租赁面积', align: 'right' },
				{ prop: 'deviceNum', label: '设备数量', align: 'right', emptyContent: '0' },
			],
		},
		EquipmentPlanProject: {
			apiName: planProjectListApi,
			editPermis: 'p_btn_property_maintenance_project_list_edit',
			infoPermis: 'p_btn_property_maintenance_project_list_view',
			rid: 'page_property_maintenance_list',
			rTitle: '设备库-保养计划',
			cloumns: [
				{ prop: 'rentalAreaSum', label: '租赁面积', align: 'right' },
				{ prop: 'planNum', label: '任务数量', align: 'right', emptyContent: '0' },
			],
		},
		FacilityProjectList: {
			apiName: facilityProjectListApi,
			editPermis: 'p_btn_property_facility_project_list_edit',
			infoPermis: 'p_btn_property_facility_project_list_view',
			rid: 'page_property_project_facility_list',
			rTitle: '设施库-设施列表',
			cloumns: [
				{ prop: 'rentalAreaSum', label: '租赁面积', align: 'right' },
				{ prop: 'facilityNum', label: '设施数量', align: 'right', emptyContent: '0' },
			],
		},
		FacilityPlanProject: {
			apiName: planFacilityProjectListApi,
			editPermis: 'p_btn_property_facility_maintenance_project_list_edit',
			infoPermis: 'p_btn_property_facility_maintenance_project_list_view',
			rid: 'page_property_facility_maintenance_list',
			rTitle: '设施库-保养计划',
			cloumns: [
				{ prop: 'rentalAreaSum', label: '租赁面积', align: 'right' },
				{ prop: 'planNum', label: '任务数量', align: 'right', emptyContent: '0' },
			],
		},
		InspectProject: {
			apiName: inspectProjectListApi,
			editPermis: 'p_btn_property_point_project_list_edit',
			infoPermis: 'p_btn_property_point_project_list_view',
			rid: 'page_property_inspection_point_config_list',
			rTitle: '巡检点位',
			cloumns: [
				{ prop: 'rentalAreaSum', label: '租赁面积', align: 'right' },
				{ prop: 'devicePointNum', label: '设备点位', align: 'right', emptyContent: '0' },
				{ prop: 'facilityPointNum', label: '设施点位', align: 'right', emptyContent: '0' },
				{ prop: 'otherPointNum', label: '其他点位', align: 'right', emptyContent: '0' },
			],
		},
		InspectPlanProject: {
			apiName: InspectPlanProjectListApi,
			editPermis: 'p_btn_property_inspection_project_list_edit',
			infoPermis: 'p_btn_property_inspection_project_list_view',
			rid: 'page_property_inspection_list',
			rTitle: '巡检计划',
			cloumns: [
				{ prop: 'rentalAreaSum', label: '租赁面积', align: 'right' },
				{ prop: 'engineeringRouteNum', label: '工程路线', align: 'right', emptyContent: '0' },
				{ prop: 'securityRouteNum', label: '安保路线', align: 'right', emptyContent: '0' },
				{ prop: 'cleaningRouteNum', label: '保洁路线', align: 'right', emptyContent: '0' },
			],
		},
		LicenseProject: {
			apiName: licenseProjectListApi,
			editPermis: 'p_btn_property_license_project_list_edit',
			infoPermis: 'p_btn_property_license_project_list_view',
			rid: 'page_property_project_license_list',
			rTitle: '证照管理',
			cloumns: [
				{ prop: 'rentalAreaSum', label: '租赁面积', align: 'right' },
				{ prop: 'licenseNum', label: '证照数量', align: 'right', emptyContent: '0' },
			],
		},
		InsuranceProject: {
			apiName: insuranceProjectListApi,
			editPermis: 'p_btn_property_insurance_project_list_edit',
			infoPermis: 'p_btn_property_insurance_project_list_view',
			rid: 'page_property_project_insurance_list',
			rTitle: '保险管理',
			cloumns: [
				{ prop: 'rentalAreaSum', label: '租赁面积', align: 'right' },
				{ prop: 'insuranceNum', label: '保险数量', align: 'right', emptyContent: '0' },
			],
		},
		SuppliesProject: {
			apiName: suppliesProjectListApi,
			editPermis: 'p_btn_property_materiel_project_list_edit',
			infoPermis: 'p_btn_property_materiel_project_list_view',
			rid: 'page_property_project_materiel_list',
			rTitle: '物料清单',
			cloumns: [
				{ prop: 'rentalAreaSum', label: '租赁面积', align: 'right' },
				{ prop: 'materielNum', label: '物料数量', align: 'right', emptyContent: '0' },
			],
		},
		WaterProject: {
			apiName: waterProjectListApi,
			editPermis: 'p_btn_property_project_watermeter_list_edit',
			infoPermis: 'p_btn_property_project_watermeter_list_view',
			rid: 'page_property_project_watermeter_list_from',
			rTitle: '水表',
			cloumns: [
				{ prop: 'rentalAreaSum', label: '租赁面积', align: 'right' },
				{ prop: 'waterMeterCount', label: '水表数', align: 'right', emptyContent: '0' },
			],
		},
		WaterCopyProject: {
			apiName: waterCopyProjectListApi,
			editPermis: 'p_btn_property_project_watermeter_readrecord_list_edit',
			infoPermis: 'p_btn_property_project_watermeter_readrecord_list_view',
			rid: 'page_property_project_watermeter_readrecord_list_from',
			rTitle: '水表抄表',
			cloumns: [
				{ prop: 'rentalAreaSum', label: '租赁面积', align: 'right' },
				{ prop: 'tenantCount', label: '商户', align: 'right', emptyContent: '0' },
			],
		},
		ElectricityProject: {
			apiName: electricityProjectListApi,
			editPermis: 'p_btn_property_project_electricmeter_list_edit',
			infoPermis: 'p_btn_property_project_electricmeter_list_view',
			rid: 'page_property_project_electricmeter_list_from',
			rTitle: '电表',
			cloumns: [
				{ prop: 'rentalAreaSum', label: '租赁面积', align: 'right' },
				{ prop: 'electricMeterCount', label: '电表数', align: 'right', emptyContent: '0' },
			],
		},
		ElectricityCopyProject: {
			apiName: electricityCopyProjectListApi,
			editPermis: 'p_btn_property_project_electricmeter_readrecord_list_edit',
			infoPermis: 'p_btn_property_project_electricmeter_readrecord_list_view',
			rid: 'page_property_project_electricmeter_readrecord_list_from',
			rTitle: '电表抄表',
			cloumns: [
				{ prop: 'rentalAreaSum', label: '租赁面积', align: 'right' },
				{ prop: 'materielNum', label: '商户', align: 'right', emptyContent: '-' },
			],
		},
		EnergyProject: {
			apiName: energyProjectListApi,
			editPermis: 'p_btn_property_water_meter_relation_project_list_edit',
			infoPermis: 'p_btn_property_water_meter_relation_project_list_view',
			rid: 'page_property_project_water_meter_relation_list',
			rTitle: '商户能源费',
			cloumns: [{ prop: 'rentalAreaSum', label: '租赁面积', width: '250', align: 'right' }],
		},
		PublicareaProject: {
			apiName: publicAreaProjectListApi,
			editPermis: 'p_btn_property_common_area_meter_project_list_edit',
			infoPermis: 'p_btn_property_common_area_meter_project_list_view',
			rid: 'page_property_project_common_area_meter_list',
			rTitle: '公区能源表',
			cloumns: [
				{ prop: 'rentalAreaSum', label: '租赁面积', width: '250', align: 'right' },
				{ prop: 'commonAreaMeterNum', label: '能源点位', align: 'right', emptyContent: '0' },
			],
		},
		ResidenceProjectList: {
			apiName: residenceProjectListApi,
			editPermis: '',
			infoPermis: '',
			rid: 'page_zhaoshang_unit_house',
			rTitle: '住宅-房间明细',
			notShowEdit: true,
			notShowDivider: true,
			cloumns: [{ prop: 'houseNum', label: '房间数量', align: 'right', emptyContent: '0' }],
		},
		ResidenceDatasyncProjectList: {
			apiName: residenceDataSyncProjectListApi,
			editPermis: '',
			infoPermis: '',
			rid: 'page_zhaoshang_unit_house_property',
			rTitle: '住宅-数据同步',
			notShowEdit: true,
			notShowDivider: true,
			cloumns: [{ prop: 'houseNum', label: '一致数量', align: 'right', emptyContent: '0' }, { prop: 'houseNoNum', label: '不一致数量', align: 'right', emptyContent: '0' }],
		},
	});
	const queryInterface = configData[routeName].apiName;
	const editPermis = configData[routeName].editPermis;
	const infoPermis = configData[routeName].infoPermis;
	const notShowEdit = configData[routeName].notShowEdit || false;
	const notShowDivider = configData[routeName].notShowDivider || false;

	function setCloumn(cloumn) {
		// cloumn[0].width = 'auto';
		configData[routeName].cloumns.push({ prop: 'empty', label: '', align: 'right', type: 'customMethods', methods: () => '' });
		return cloumn.concat(configData[routeName].cloumns);
	}

	function toPage(row, pageType) {
		router.push({ path: '/page/routeController/index', query: { rid: configData[routeName].rid, rTitle: configData[routeName].rTitle, projectCode: row.projectCode, projectName: row.name, pageType: pageType } });
	}
</script>
